#include "StdAfx.h"
#include "CircuitRoundRectDisObj.h"


CCircuitRoundRectDisObj::CCircuitRoundRectDisObj(CCircuitRoundRect *pCirRoundRect)
	: CCircuitUnitDisObj(pCirRoundRect)
{
	m_dblColor[0] = pCirRoundRect->GetBorderColorR();
	m_dblColor[1] = pCirRoundRect->GetBorderColorG();
	m_dblColor[2] = pCirRoundRect->GetBorderColorB();
	m_dblLineWidth = pCirRoundRect->GetBorderWidth();
}

CCircuitRoundRectDisObj::CCircuitRoundRectDisObj(const CCircuitRoundRectDisObj *pDisObj, CCircuitRoundRect *pCirRoundRect/* =NULL */)
	: CCircuitUnitDisObj(pDisObj, pCirRoundRect)
{

}

CCircuitRoundRectDisObj::~CCircuitRoundRectDisObj(void)
{
}

void CCircuitRoundRectDisObj::Serialize(CArchive & ar)
{
	CCircuitUnitDisObj::Serialize(ar);
}

void CCircuitRoundRectDisObj::Display(CHoopsMap *pHoopsMap)
{
	CCircuitRoundRect *pCirRect = (CCircuitRoundRect *)GetEntityObj();
	if (!pCirRect)
	{
		return;
	}

	HC_KEY key_obj = INVALID_KEY;
	char sCirRectSeg[64];
	sprintf(sCirRectSeg, "rect_%d", pCirRect->GetId());
	key_obj = HC_Open_Segment(sCirRectSeg);
		HC_Flush_Contents(".", "everything");

		double x1 = pCirRect->GetStartPosX();
		double y1 = pCirRect->GetStartPosY();
		double x2 = pCirRect->GetEndPosX();
		double y2 = pCirRect->GetEndPosY();
		if (pCirRect->IsFill())
		{
			CDisplayObj::InsertFilledRectCround(".", x1, y1, x2, y2);
		}
		else
		{
			CDisplayObj::InsertRectRound(".", x1, y1, x2, y2);
		}

		HC_Set_Edge_Weight(pCirRect->GetBorderWidth());

		char szColorPattern[64];
		sprintf(szColorPattern, "edges = (r=%.2f g=%.2f b=%.2f), faces = (r=%.2f g=%.2f b=%.2f)",
			GetColorR(), GetColorG(), GetColorB(), 
			pCirRect->GetFillColorR(), pCirRect->GetFillColorG(), pCirRect->GetFillColorB());
		HC_Set_Color(szColorPattern);
	HC_Close_Segment();

	pHoopsMap->Delete(this);
	pHoopsMap->Add(key_obj, this);
}

void CCircuitRoundRectDisObj::Transform(const CMatrix transf)
{

}

CObj *CCircuitRoundRectDisObj::Clone() const
{
	return new CCircuitRoundRectDisObj(this);
}

bool CCircuitRoundRectDisObj::GetBox(double & dblLeft, double & dblBottom, double & dblRight, double & dblTop) const
{
	return false;
}

eCircuitUnitType CCircuitRoundRectDisObj::GetCircuitUnitType() const
{
	return CIRCUIT_ROUNDRECT_DISOBJ;
}
